﻿@page "/"

<h1>Blazored FluentValidation Sample</h1>

<hr class="mb-5" />

<EditForm Model="@Person" OnValidSubmit="@SubmitValidForm">
    <FluentValidationValidator @ref="fluentValidationValidator" />
    <ValidationSummary />

    <p>
        <label>First Name: </label>
        <InputText @bind-Value="@Person.FirstName" />
        <ValidationMessage For="@(() => Person.FirstName)" />
    </p>

    <p>
        <label>Last Name: </label>
        <InputText @bind-Value="@Person.LastName" />
        <ValidationMessage For="@(() => Person.LastName)" />
    </p>

    <hr />

    <p>
        <label>Age: </label>
        <InputNumber @bind-Value="@Person.Age" />
        <ValidationMessage For="@(() => Person.Age)" />
    </p>

    <p>
        <label>Email Address: </label>
        <InputText @bind-Value="@Person.EmailAddress" />
        <ValidationMessage For="@(() => Person.EmailAddress)" />
    </p>

    <p>
        <label>Address: Line 1: </label>
        <InputText @bind-Value="@Person.Address.Line1" />
        <ValidationMessage For="@(() => Person.Address.Line1)" />
    </p>

    <p>
        <label>Address: Line 2: </label>
        <InputText @bind-Value="@Person.Address.Line2" />
    </p>

    <p>
        <label>Address: Town: </label>
        <InputText @bind-Value="@Person.Address.Town" />
        <ValidationMessage For="@(() => Person.Address.Town)" />
    </p>

    <p>
        <label>Address: County: </label>
        <InputText @bind-Value="@Person.Address.County" />
        <ValidationMessage For="@(() => Person.Address.County)" />
    </p>

    <p>
        <label>Address: Postcode: </label>
        <InputText @bind-Value="@Person.Address.Postcode" />
        <ValidationMessage For="@(() => Person.Address.Postcode)" />
    </p>

    <button type="submit">Save</button>

</EditForm>
<br />
<button @onclick="PartialValidate">Partial Validation</button>

@code {
    Person Person { get; set; } = new Person();

    private FluentValidationValidator fluentValidationValidator;

    void SubmitValidForm()
    {
        Console.WriteLine("Form Submitted Successfully!");
    }

    void PartialValidate()
    {
        Console.WriteLine($"Partial validation result : {fluentValidationValidator.Validate(options => options.IncludeRuleSets("Names"))}");
    }
}